<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Chain Select With Codeigniter and Jquery</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js" type="text/javascript"></script>
        <script type="text/javascript">

        $(document).ready(function () {
        /*™*******************************************************************************************™*/


        	
        	 $( "#BTTnewrow" ).click(function() {

        	 
            	
        		var num_row = $("#HIDnum_row").val();

  


        		num_row = parseFloat(num_row) + parseFloat(1);
        		$("#HIDnum_row").val(num_row);



                 $.ajax({
                         type: "POST",
                         url : "<?php echo site_url('chain/selectSubprovince')?>",
                         success: function(msg){
                             $('.province'+num_row).html(msg);
                         }

                 });

               
        
     
                
        		$("<div class='#'>Province : </div><select class='province"+num_row+"'></select><br>District : <br><select name='district' id='district"+num_row+"'><option value='0'>--- SELECT DISTRICT ---</option></select>").insertBefore("#addNewRow");
        			
        		
        		

            });


        	
            
            
           
            
            

        });
         



        	


        </script>
  </head>
  <body>
    <!-- page content -->
    <?php //echo form_open('chain/submit'); ?>
    <div style="display:block; list-style:none">
    <ol>
    <div id="pro">
    Province : <br/>
    <?php
        echo form_dropdown("pro_id",$option_province,"","id='pro_id'");
    ?>
    </div>
 
    <div id="dis">
    District :<br/>
    <?php
        echo form_dropdown("dis_id",array('--- SELECT DISTRICT ---'=>'--- SELECT DISTRICT ---'),'','disabled',"id='dis_id'" );
    ?>
    </div>
    
    
    
    
     <div id="addNewRow"></div>
     <input type="hidden" id="HIDnum_row" name="HIDnum_row" value="1" />
 	 <input type="submit" id="BTTnewrow" name="BTTnewrow" value="Add Branch" " />
 
    
    </ol>
    </div>
  <?php // echo form_submit("submit","Submit"); ?> 
    <?php echo form_close(); ?>
    <script type="text/javascript">
        $("#pro_id").change(function(){
                var selectValues = $("#pro_id").val();
                if (selectValues == 0){
                    var msg = "province / Region :<br><select name=\"dis_id\" disabled><option value=\"Pilih province / Kabupaten\">Pilih country Dahulu</option></select>";
                    $('#dis').html(msg);
                }else{
                    var pro_id = {pro_id:$("#pro_id").val()};
                    $('#dis_id').attr("disabled",true);
                    $.ajax({
                            type: "POST",
                            url : "<?php echo site_url('chain/selectdistrict/"+selectValues+"')?>",
                            success: function(msg){
                                $('#dis').html(msg);
                            }
                    });
                }
        });
           
       </script>
  </body>
</html>